import 'package:doctor_login_lib/certification/page.dart';
import 'package:doctor_login_lib/doctor_login_lib.dart';
import 'package:doctor_login_lib/component.dart';
import 'package:doctor_login_lib/set_user_info/page.dart';
import 'package:flutter/material.dart';
import 'package:doctor_login_lib/login/page.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:base_lib/index.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  DoctorLoginLib.doInit();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return ReminderWrapper(
      MaterialApp(
        localizationsDelegates: [
          GlobalMaterialLocalizations.delegate,
          GlobalCupertinoLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
        ],
        supportedLocales: [
          const Locale('zh', 'CH'),
          const Locale('en', 'US'),
        ],
        locale: Locale('zh'),
        title: '医生端登录组件示例',
        theme: ThemeData(
          primarySwatch: Colors.blue,
          visualDensity: VisualDensity.adaptivePlatformDensity,
        ),
        home: MyHomePage(title: '医生端登录组件示例'),
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      DoctorLoginLib.initWithContext(context);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            RaisedButton(
              onPressed: () {
                Navigator.push(context,
                    MaterialPageRoute(builder: (BuildContext context) {
                  return LoginPage(null);
                  // return SetUserInfoPage(null);
                }));
              },
              child: Text("登录组件"),
            ),
            RaisedButton(
              onPressed: () {
                DoctorLoginLib.validateDoctorToken(context);
              },
              child: Text("验证token"),
            ),
          ],
        ),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
